import Vue from 'vue'
import Router from 'vue-router'
import Register from './Register'
import Login from './Login'
import Userinfo from './Userinfo'
import Edit from './Edit'
import Home from './Home'
import Article from './Article'
import EditCategory from './EditCategory'
Vue.use(Router)


const router=new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
   Register,
   Login,
   Userinfo,
   Edit,
   Home,
   Article,
   EditCategory
  ]
})
router.beforeEach((to,from,next) => {
  if((!localStorage.getItem('token') || !localStorage.getItem('id'))&&to.meta.istoken == true){
    router.push('/login')
    Vue.prototype.$msg.fail('请重新登录')
    return
  }
  next()
})

export default router
